package com.patent.service.impl;

import com.patent.dao.PatentOrderMapper;
import com.patent.domain.po.PatentOrder;
import com.patent.service.InvoiceAmountService;
import com.patent.service.PatentOrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service("patentOrderService")
@Transactional
public class PatentOrderServiceImpl implements PatentOrderService {

	private static final Logger log = LoggerFactory.getLogger(PatentOrderServiceImpl.class);

	@Resource(name="patentOrderMapper")
	private PatentOrderMapper patentOrderMapper;

	@Resource(name="invoiceAmountService")
	private InvoiceAmountService invoiceAmountService;

	@Override
	public PatentOrder selectByPrimaryKey(Integer id) throws Exception {
		return patentOrderMapper.selectByPrimaryKey(id);
	}

	@Override
	public PatentOrder queryByOrderNo(String orderNo) {
		return patentOrderMapper.queryByOrderNo(orderNo);
	}

	@Override
	public void updateByPrimaryKeySelective(PatentOrder patentOrder) {
		patentOrderMapper.updateByPrimaryKeySelective(patentOrder);
	}

	@Override
	public void updateRecordP(PatentOrder patentOrder) {
		try {
			updateByPrimaryKeySelective(patentOrder);
			invoiceAmountService.dealInvoiceAmount("add", patentOrder.getUserMobile(), patentOrder.getPayAmount());
		} catch (Exception e) {
			e.printStackTrace();
			log.error("修改专利信息失败：" + e.getMessage());
			throw new RuntimeException(e);
		}
	}
}
